<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>操作系统学习笔记-I/O管理和磁盘调度 | 花猪のBlog</title><meta name="keywords" content="操作系统"><meta name="author" content="花猪,2296412185@qq.com"><meta name="copyright" content="花猪"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="记录操作系统学习历程">
<meta property="og:type" content="article">
<meta property="og:title" content="操作系统学习笔记-I&#x2F;O管理和磁盘调度">
<meta property="og:url" content="https://cnhuazhu.top/2021/06/02/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-I-O%E7%AE%A1%E7%90%86%E5%92%8C%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6/index.html">
<meta property="og:site_name" content="花猪のBlog">
<meta property="og:description" content="记录操作系统学习历程">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png">
<meta property="article:published_time" content="2021-06-02T12:02:45.000Z">
<meta property="article:modified_time" content="2021-06-24T08:55:34.006Z">
<meta property="article:author" content="花猪">
<meta property="article:tag" content="操作系统">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png"><link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/avatar.jpg"><link rel="canonical" href="https://cnhuazhu.top/2021/06/02/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-I-O%E7%AE%A1%E7%90%86%E5%92%8C%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":60,"languages":{"author":"作者: 花猪","link":"链接: ","source":"来源: 花猪のBlog","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#ABADAC","bgDark":"#121212","position":"bottom-right"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '操作系统学习笔记-I/O管理和磁盘调度',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-06-24 16:55:34'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><link rel="stylesheet" href="/css/tag.css"><link rel="stylesheet" href="/css/pagelucency.css"><style>#article-container.post-content h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { -webkit-animation: avatar_turn_around 1s linear infinite; -moz-animation: avatar_turn_around 1s linear infinite; -o-animation: avatar_turn_around 1s linear infinite; -ms-animation: avatar_turn_around 1s linear infinite; animation: avatar_turn_around 1s linear infinite; }</style><link rel="stylesheet" href="/css/avatarbg.css"><link rel="stylesheet" href="/css/footerlucency.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><link rel="stylesheet" href="/css/mouse.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-swiper/lib/swiper.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-swiper/lib/swiperstyle.css"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.3.0"><link rel="alternate" href="/atom.xml" title="花猪のBlog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="wizard-scene"><div class="wizard-objects"><div class="wizard-square"></div><div class="wizard-circle"></div><div class="wizard-triangle"></div></div><div class="wizard"><div class="wizard-body"></div><div class="wizard-right-arm"><div class="wizard-right-hand"></div></div><div class="wizard-left-arm"><div class="wizard-left-hand"></div></div><div class="wizard-head"><div class="wizard-beard"></div><div class="wizard-face"><div class="wizard-adds"></div></div><div class="wizard-hat"><div class="wizard-hat-of-the-hat"></div><div class="wizard-four-point-star --first"></div><div class="wizard-four-point-star --second"></div><div class="wizard-four-point-star --third"></div></div></div></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">86</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="http://cnhuazhu.top/"><i class="fa-fw fas fa-gift"></i><span> 引导</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-sitemap"></i><span> 分站</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="http://cnhuazhu.top/next"><i class="fa-fw fas fa-chevron-right"></i><span> Next</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-list"></i><span> 文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 图库</span></a></li><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book"></i><span> 阅读</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-film"></i><span> 电影</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fa fa-video"></i><span> 视频</span></a></li><li><a class="site-page child" href="/artitalk/"><i class="fa-fw fas fa-quote-left"></i><span> 说说</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-list"></i><span> 链接</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></li><li><a class="site-page child" href="/website/"><i class="fa-fw fas fa-globe"></i><span> 网站</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/Message/"><i class="fa-fw fas fa-comment"></i><span> 留言</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background: transparent"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">花猪のBlog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="http://cnhuazhu.top/"><i class="fa-fw fas fa-gift"></i><span> 引导</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-sitemap"></i><span> 分站</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="http://cnhuazhu.top/next"><i class="fa-fw fas fa-chevron-right"></i><span> Next</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-list"></i><span> 文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 图库</span></a></li><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book"></i><span> 阅读</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-film"></i><span> 电影</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fa fa-video"></i><span> 视频</span></a></li><li><a class="site-page child" href="/artitalk/"><i class="fa-fw fas fa-quote-left"></i><span> 说说</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fas fa-list"></i><span> 链接</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></li><li><a class="site-page child" href="/website/"><i class="fa-fw fas fa-globe"></i><span> 网站</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/Message/"><i class="fa-fw fas fa-comment"></i><span> 留言</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">操作系统学习笔记-I/O管理和磁盘调度</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-06-02T12:02:45.000Z" title="发表于 2021-06-02 20:02:45">2021-06-02</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-06-24T08:55:34.006Z" title="更新于 2021-06-24 16:55:34">2021-06-24</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">学习笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">5.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>17分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="操作系统学习笔记-I/O管理和磁盘调度"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1>前言</h1>
<p><em>正在学习操作系统，记录笔记。</em></p>
<blockquote>
<p>参考资料：</p>
<p>《操作系统（精髓与设计原理 第8版） 》</p>
</blockquote>
<hr>
<h1>第十一章：I/O管理和磁盘调度</h1>
<h2 id="I-O设备">I/O设备</h2>
<p>I/O设备大体上可以分为如下三类：</p>
<ul>
<li>人可读：顾名思义就是其面向的用户群体是人，具体有：
<ul>
<li>打印机</li>
<li>终端（包含：显示器、键盘、鼠标等）</li>
</ul>
</li>
<li>机器可读：面向电子设备通信，具体有：
<ul>
<li>磁盘、磁带驱动器</li>
<li>传感器</li>
<li>控制器</li>
</ul>
</li>
<li>通信：适用于与远程设备通信，如：
<ul>
<li>数字线路驱动器</li>
<li>调制解调器</li>
</ul>
</li>
</ul>
<p>数据传送速率：不同类型的I/O设备，数据传送速率可能会相差几个数量级，如下图：</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E4%B8%8D%E5%90%8CIO%E8%AE%BE%E5%A4%87%E7%9A%84%E9%80%9F%E7%8E%87.png" alt=""></p>
<p>用途：设备用途对操作系统及其支撑设施中的软件和策略都有影响。</p>
<ul>
<li>用于存储文件的磁盘需要文件管理软件的支持</li>
<li>虚拟内存需要特殊硬件软件支持</li>
<li>终端既可被普通用户使用，也可被系统管理员使用。</li>
</ul>
<p>控制的复杂性：例如，打印机仅需要一个相对简单的控制接口，而磁盘的控制接口则要复杂得多。</p>
<p>传送单位：数据可按字节流或字符流的形式传送（如终端I/O），也可按更大的块传送（如磁盘I/O）。</p>
<p>错误条件：随着设备的不同，错误的性质、报告错误的方式、错误造成的后果及有效的响应范围，都各不相同。</p>
<blockquote>
<p>以上的差异使得不管是从操作系统的角度，还是从用户进程的角度，都很难找到一种统一的、一致的I/O解决方法。</p>
</blockquote>
<h2 id="I-O功能的组织">I/O功能的组织</h2>
<p>有三种执行I/O的技术（具体可以看<a target="_blank" rel="noopener external nofollow noreferrer" href="https://cnhuazhu.gitee.io/2021/03/14/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F%E6%A6%82%E8%BF%B0/">第一章</a>的内容，这里不过多介绍）：</p>
<ul>
<li>
<p>可编程I/O：处理器代表一个进程给I/O模块发送一个I/O命令；该进程进入忙等待，直到操作完成才能继续执行。</p>
<blockquote>
<p>缺点：当执行I/O操作时，处理器容易进入忙等待状态（空闲），造成处理器资源浪费。</p>
</blockquote>
</li>
<li>
<p>中断驱动I/O：处理器代表进程向I/O模块发出一个I/O命令。有两种可能性：</p>
<ul>
<li>
<p>若来自进程的I/O指令是非阻塞的，则处理器继续执行发出I/O命令的进程的后续指令。</p>
</li>
<li>
<p>若I/O指令是阻塞的，则处理器执行的下一条指令来自操作系统，它将当前的进程设置为阻塞态并调度其他进程。</p>
<blockquote>
<p>引入中断机制。</p>
<p>缺点：虽然缓解了忙等待状况，但是最后数据在I/O设备与主存之间传输的过程要依赖于处理器。</p>
</blockquote>
</li>
</ul>
</li>
<li>
<p>直接存储器访问（Direct Memory Access，DMA）：一个DMA模块（作为“代理CPU”）控制内存和I/O模块之间的数据交换。为传送一块数据，处理器给DMA模块发请求，且只有在整个数据块传送结束后，它才被中断。</p>
<blockquote>
<p>数据在I/O设备与主存之间传输的整个过程只产生两次中断：</p>
<ul>
<li>在调用I/O设备前，处理器向I/O设备发出指令</li>
<li>数据传输完之后，DMA模块向I/O设备发出中断（告知“数据传输完毕”）</li>
</ul>
<p>优势：数据在I/O设备与主存之间传输不依赖于处理器。</p>
</blockquote>
</li>
</ul>
<p>小结I/O执行技术</p>
<table>
<thead>
<tr>
<th></th>
<th>无中断</th>
<th>使用中断</th>
</tr>
</thead>
<tbody>
<tr>
<td>通过处理器实现I/O和内存间的传送</td>
<td>可编程I/O</td>
<td>中断驱动I/O</td>
</tr>
<tr>
<td>I/O和内存间直接传送</td>
<td></td>
<td>直接存储器访问（DMA）</td>
</tr>
</tbody>
</table>
<h3 id="I-O功能的发展">I/O功能的发展</h3>
<ol>
<li>
<p>处理器直接控制外围设备：这在简单的微处理器控制设备中可以见到。</p>
</li>
<li>
<p>增加了控制器或I/O模块：引入无中断的可编程I/O。</p>
<blockquote>
<p>从该阶段开始，处理器无需处理外部设备的细节。</p>
</blockquote>
</li>
<li>
<p>同上一阶段基本相同，但是采用了中断的方式：处理器无须费时间等待执行一次I/O操作，因而提高了效率。</p>
</li>
<li>
<p>DMA模块的引入：数据块在I/O设备和内存中移动无需处理器参与，仅在传送开始和结束时才需要用到处理器。</p>
</li>
<li>
<p>I/O模块有一个独立处理器：有专门为I/O设计的指令集，中央处理器指导I/O处理器执行内存中的一个I/O程序。I/O处理器在没有中央处理器干涉的情况下取指令并执行这些指令。这就使得中央处理器可以指定一系列的I/O活动，且仅在整个序列执行完成后中央处理器才被中断。</p>
<blockquote>
<p>该阶段的I/O模块通常称为：I/O channel (I/O通道)</p>
</blockquote>
</li>
<li>
<p>I/O模块有自己的局部存储器，事实上其本身就是一台计算机：</p>
<ul>
<li>使用这种体系结构可以控制许多I/O设备，并使需要中央处理器参与的部分降到最小</li>
<li>这种结构通常用于控制与交互终端的通信，I/O处理器负责大多数控制终端的任务</li>
</ul>
<blockquote>
<p>该阶段的I/O模块通常称为：I/O processor (I/O处理器)</p>
</blockquote>
</li>
</ol>
<h3 id="直接存储器访问（DMA）">直接存储器访问（DMA）</h3>
<p>下图是典型的DMA框图</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSDMA%E6%A1%86%E5%9B%BE.png" alt=""></p>
<blockquote>
<p>说明：</p>
<ul>
<li>Data Count：保存此次传输的数据的字节数</li>
<li>Data Register：存放正在传输的数据</li>
<li>Address Register：基址寄存器</li>
<li>Control Logic：其他的一些功能</li>
</ul>
<p>DMA工作流程：</p>
<ol>
<li>处理器和DMA模块之间有读写控制线，基于此处理器可以向DMA模块发送命令（请求I/O）</li>
<li>DMA模块直接负责I/O设备到内存之间的数据传输（不需要处理器）</li>
<li>在数据传输完之后，DMA模块向处理器发送一个中断信号</li>
</ol>
</blockquote>
<p>DMA机制的配置：</p>
<ul>
<li>
<p>所有模块共享同一个系统总线：</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSDMA%E6%9C%BA%E5%88%B6%E4%B8%80.png" alt=""></p>
<ul>
<li>DMA模块充当代理处理器</li>
<li>同一时刻只允许一个I/O设备和主存进行交互，否则会出现数据冲突</li>
<li>同一个时间段可以有多台I/O设备和主存进行交互——分时复用</li>
<li>排队的情况很严重，虽然这样的设计开销不大，但是效率很低</li>
</ul>
</li>
<li>
<p>集成DMA和I/O：</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSDMA%E6%9C%BA%E5%88%B6%E4%BA%8C.png" alt=""></p>
<ul>
<li>
<p>减少了I/O对DMA模块的竞争</p>
<blockquote>
<p>在DMA模块和一个或多个I/O模块之间还存在一条不包含系统总线的路径。DMA逻辑实际上可能就是I/O模块的一部分，或可能是控制一个或多个I/0模块的一个单独模块。</p>
</blockquote>
</li>
</ul>
</li>
<li>
<p>增加I/O局部总线：</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSDMA%E6%9C%BA%E5%88%B6%E4%B8%89.png" alt=""></p>
<ul>
<li>DMA模块中I/O接口的数量减少到1</li>
<li>易扩展</li>
</ul>
<blockquote>
<p>第二、三种方式：DMA和I/O模块之间的数据交换是脱离系统总线完成的。</p>
</blockquote>
</li>
</ul>
<h2 id="操作系统设计问题">操作系统设计问题</h2>
<h3 id="设计目标">设计目标</h3>
<p>在设计I/O机制时，最重要的两个目标就是：效率（Efficiency）、通用性（Generality）。</p>
<ul>
<li>
<p>效率：</p>
<ul>
<li>
<p>I/O操作通常是计算机系统的瓶颈。</p>
<blockquote>
<p>之前也提到过，大多数I/O设备都是机械运动，而处理器是电信号的处理，二者的速度差距在几个数量级。</p>
</blockquote>
</li>
<li>
<p>解决上述问题的一种方式是引入多道程序设计。这样可以缓解，但不能彻底解决问题。我们想象一种极端情况：在并发度达到最大时，所有的进程都在等待I/O设备，那么这时也会出现CPU空闲状态，效率并不能有效提高。</p>
</li>
<li>
<p>于是引入交换技术。用于将额外的就绪进程加载进内存，从而使处理器处于工作状态。（这本身就是一个I/O操作）</p>
</li>
</ul>
</li>
<li>
<p>通用性：处于简单和避免错误的考虑，希望能用一种统一的方式处理所有设备。</p>
<blockquote>
<p>注：有些版本将“通用性”翻译为“设备的独立性”。</p>
</blockquote>
<ul>
<li>
<p>处理器看待I/O设备的方式统一。</p>
</li>
<li>
<p>操作系统管理I/O设备和IVO操作的方式统一。</p>
<blockquote>
<p>由于设备特性的多样性，在实际中很难真正实现通用性。</p>
<p>目前所能做的就是用一种层次化、模块化的方法设计I/O功能。这种方法隐藏了大部分I/O设备低层例程中的细节，使得用户进程和操作系统高层可以通过如读、写、打开、关闭、加锁和解锁等通用的函数来操作I/O设备。</p>
</blockquote>
</li>
</ul>
</li>
</ul>
<h3 id="I-O功能的逻辑结构">I/O功能的逻辑结构</h3>
<p>分层的原理是：操作系统的功能可以根据其复杂性、特征时间尺度和抽象层次来分开。</p>
<p>将分层原理应用于I/O机制，具体如下图：</p>
<h3 id="img-src-https-cdn-jsdelivr-net-gh-CNhuazhu-Image-OSIO层次结构-png-style-zoom-80"><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSIO层次结构.png" style="zoom:80%;" /></h3>
<blockquote>
<p>说明：</p>
<ul>
<li>逻辑I/O（Logical I/O）：逻辑I/O模块把设备当作一个逻辑资源来处理，它并不关心实际控制设备的细节。</li>
<li>设备I/O（Device I/O）：请求的操作和数据（缓冲的数据、记录等）被转换为适当的I/O指令序列、通道命令和控制器命令。</li>
<li>调度和控制（Scheduling &amp; control）：I/O操作的排队、调度实际上发生在这一层。</li>
<li>目录管理（Directory management）：在这一层，符号文件被转换为标识符，采用标识符时可通过文件描述符表或索引表直接或间接地访问文件。</li>
<li>文件系统（File system）：这一层处理文件的逻辑结构及用户指定的操作，如打开、关闭、读、写等。这一层还管理访问权限。</li>
<li>物理组织（Physical organization）：考虑到辅存设备的物理磁道和扇区结构，对于文件和记录的逻辑访问必须转换为物理外存地址。辅助存储空间和内存缓冲区的分配通常也在这一层处理。</li>
</ul>
</blockquote>
<h2 id="I-O缓冲">I/O缓冲</h2>
<p>缓存（buffering）的原因：</p>
<ul>
<li>处理器在I/O完成之前必须等待</li>
<li>在页交换的过程中，某些页必须驻留内存</li>
</ul>
<blockquote>
<p>缓存（buffer）：内存当中预留的一个区域，用来暂存I/O通讯的数据。</p>
<p>举例：</p>
<ul>
<li>printf函数：可能有时候会出现明明在程序中写了printf，但是并没有如期望般那样得到输出结果。这是因为printf是一个带缓冲的输出打印。printf本身会调用一个系统调用，会产生进程切换，如果仅为了打印一句“Hello World”就使用进程切换，可以认为这是没必要的。所以会当缓冲区满了的时候再一次性打印出来。（如果必要，我们也可以用fflush去强制清除缓存，将其打印出来）</li>
<li>打印机：在使用打印机的时候可以看到计算机屏幕上显示进度条（完成一页、两页…），待到进度条完成之后，打印机才开始工作。进度条展示的其实就是将数据存储到缓冲区的进度，当执行完成后，处理器就可以完成其他的任务去了，接下来才是打印机去访问缓冲区，将数据真实地打印出来。</li>
</ul>
<p>优点：</p>
<ul>
<li>可以让CPU和I/O并行操作</li>
<li>减少中断次数</li>
<li>提高CPU效率</li>
</ul>
</blockquote>
<p>缓冲的定义：在输入请求发出前就开始执行输入传送，并且在输出请求发出一段时间之后才开始执行输出传送。</p>
<blockquote>
<p>光看定义可能有些不知所云，往下看，慢慢体会。</p>
</blockquote>
<p>在讨论各种缓冲方法之前，首先要区分两类I/O设备：</p>
<ul>
<li>面向块（Block-oriented）的I/O设备：
<ul>
<li>将信息保存到固定大小的块中</li>
<li>传送过程中一次传输一块</li>
<li>通常可以通过块号访问数据</li>
<li>举例：磁盘、磁带、USB智能卡</li>
</ul>
</li>
<li>面向流（Stream-oriented）的I/O设备：
<ul>
<li>以字节流的方式输入\输出数据</li>
<li>举例：终端、打印机、通信端口、鼠标和其他指示设备及其他大多数非辅存设备</li>
</ul>
</li>
</ul>
<h3 id="单缓冲">单缓冲</h3>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E5%8D%95%E7%BC%93%E5%86%B2.png" alt=""></p>
<ul>
<li>I/O设备先将传送的数据移入到系统缓冲区中（I/O → 内存）</li>
<li>上一步传输完成时，进程把该块移动到用户空间（内存 → 内存）</li>
<li>紧接着，根据局部性原理，会预先请求另一个数据块，将其移入缓冲区（预读；或预先输入）</li>
</ul>
<p>优点：</p>
<ul>
<li>用户进程可在下一数据块读取的同时，处理已读入的数据块</li>
<li>输入发生在系统内存而非用户进程内存，因此操作系统可以将该进程换出</li>
</ul>
<p>缺点：</p>
<ul>
<li>
<p>操作系统必须记录给用户进程分配系统缓冲区的情况</p>
<blockquote>
<p>操作系统维护用户进程系统缓冲区。</p>
</blockquote>
</li>
<li>
<p>交换逻辑也受到影响</p>
<blockquote>
<p>I/O操作所涉及的磁盘和用于交换的磁盘是同一个磁盘时，磁盘写操作排队等待将进程换出到同一个设备上是没有任何意义的。若试图换出进程并释放内存，则要在I/O操作完成后才能开始，而在这时，把进程换出到磁盘已经不再合适。</p>
</blockquote>
</li>
</ul>
<p>面向流的单缓冲：</p>
<ul>
<li>每次传送一行的方式或每次传送一字节的方式</li>
<li>用户在终端每次输入一行，用回车表示到达行尾</li>
<li>输出到终端时也是类似地每次输出一行</li>
</ul>
<h3 id="双缓冲">双缓冲</h3>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E5%8F%8C%E7%BC%93%E5%86%B2.png" alt=""></p>
<ul>
<li>
<p>在内存中为操作系统分配两个系统缓冲区</p>
</li>
<li>
<p>输入输出交替使用</p>
<blockquote>
<p>在一个进程向一个缓冲区中传送数据（从这个缓冲区中取数据）的同时，操作系统正在清空（或填充）另一个缓冲区，这种技术称为双缓冲（double buffering）或缓冲交换（buffer swapping）。</p>
</blockquote>
</li>
</ul>
<h3 id="循环缓冲">循环缓冲</h3>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E5%BE%AA%E7%8E%AF%E7%BC%93%E5%86%B2.png" alt=""></p>
<ul>
<li>内存中有两个以上的缓冲区</li>
<li>每个单缓冲区是循环缓冲器的一个单元</li>
<li>平滑I/O操作和进程之间的数据流</li>
</ul>
<h2 id="磁盘调度">磁盘调度</h2>
<h3 id="磁盘性能">磁盘性能</h3>
<p>磁盘的内部结构如下图：</p>
<img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS磁盘模型1.png" style="zoom: 50%;" />
<blockquote>
<p>说明：为了读或写，磁头必须定位于指定的磁道和该磁道中指定扇区的开始处。</p>
</blockquote>
<p>磁盘性能参数：</p>
<ul>
<li>寻道时间（Seek time ）：磁头定位到磁道所需要的时间称为寻道时间。</li>
<li>旋转延迟（Rotational delay ）：磁头到达扇区开始位置的时间称为旋转延迟。</li>
<li>传输时间（transfer time）：磁头定位完成就开始读操作或写操作，这就是数据传输，传输的时间就是传输时间。</li>
</ul>
<p><strong>磁盘调度（重点）</strong>：</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E7%A3%81%E7%9B%98%E7%9A%84%E6%80%A7%E8%83%BD.png" alt=""></p>
<p>上图为磁盘I/O传送的一般时序图：</p>
<p><strong>等待I/O设备 → 等待通道 → 寻道（确定磁道） → 旋转延迟（确定扇区） → 数据传输延迟</strong></p>
<blockquote>
<p>相关计算：</p>
<p>传输时间：</p>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>T</mi><mo>=</mo><mfrac><mi>b</mi><mrow><mi>r</mi><mi>N</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">T = \frac{b}{rN}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.05744em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.37144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p>
<ul>
<li>T：传输时间</li>
<li>b：要传送的字节数</li>
<li>N：一个磁道中的字节数</li>
<li>r：旋转速度（单位：转/秒）</li>
</ul>
<p>总平均存取时间：</p>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>T</mi><mi>a</mi></msub><mo>=</mo><msub><mi>T</mi><mi>s</mi></msub><mo>+</mo><mfrac><mn>1</mn><mrow><mn>2</mn><mi>r</mi></mrow></mfrac><mo>+</mo><mfrac><mi>b</mi><mrow><mi>r</mi><mi>N</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">T_a = T_s + \frac{1}{2r} +\frac{b}{rN}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">a</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:2.00744em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">2</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:2.05744em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.37144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p>
<ul>
<li>T<sub>s</sub>：平均寻道时间</li>
</ul>
</blockquote>
<h3 id="磁盘调度策略">磁盘调度策略</h3>
<p>不同磁盘调度的性能差异的原因可以追溯到寻道时间。因此为了提高性能，需要减少花费在寻道上的时间。</p>
<p>考虑多道程序环境中的一种典型情况：即操作系统为每个I/O设备维护一个请求队列。</p>
<ul>
<li>对于一个磁盘来说，队列中可能有来自多个进程的许多I/O请求（读和写）</li>
<li>随机调度（random scheduling）：随机访问磁道。该种方法性能最差，可用于评估其他技术。</li>
</ul>
<p>下面我们将会介绍八种磁盘调度策略，在介绍时会统一以一个例子进行：</p>
<blockquote>
<p>例子：</p>
<p>假设磁盘有200个磁道，磁盘请求队列中是一些随机请求。被请求的磁道，按照磁盘调度程序的接收顺序分别为：</p>
<p><strong>55、58、39、18、90、160、150、38、184</strong></p>
<p>说明：</p>
<p>假设以磁道号为100处开始寻道。</p>
<p>具体以折线图的形式展示：纵轴表示磁盘上的磁道；横轴表示时间（或跨越磁道的数量）。</p>
</blockquote>
<h4 id="优先级（Priority，PRI）">优先级（Priority，PRI）</h4>
<ul>
<li>此方法不会优化磁盘的利用率</li>
<li>通常较短的批作业和交互作业的优先级较高</li>
<li>可以提供较好的交互响应时间</li>
</ul>
<h4 id="先进先出（First-in-First-out，FIFO）">先进先出（First-in First-out，FIFO）</h4>
<p>处理请求的顺序（如下图）：<code>55、58、39、18、90、160、150、38、184</code></p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6%E5%85%88%E8%BF%9B%E5%85%88%E5%87%BA.png" alt=""></p>
<ul>
<li>这是最简单的调度策略</li>
<li>按照收到请求的顺序进行处理</li>
<li>优点：公平对待每个请求</li>
<li>缺点：并未对磁头的访问有任何优化，效率最差。在多进程环境中，性能接近随机调度。</li>
</ul>
<h4 id="后进先出（Last-in-First-out，LIFO）">后进先出（Last-in First-out，LIFO）</h4>
<p>处理请求的顺序：<code>184、38、150、160、90、18、39、58、55</code></p>
<ul>
<li>
<p>考虑到了局部性原理</p>
<blockquote>
<p>在事物处理系统中，由于顺序读取文件的缘故，把设备分配给最后到来的用户，可减少磁臂的运动，甚至没有磁臂运动。</p>
</blockquote>
</li>
<li>
<p>缺点：可能会产生饥饿</p>
<blockquote>
<p>假设队列中不停地有新的请求，那么最先进入队列的请求很可能饥饿。</p>
</blockquote>
</li>
</ul>
<h4 id="最短服务时间优先（Shortest-Service-Time-First-，SSTF）">最短服务时间优先（Shortest Service Time First ，SSTF）</h4>
<p>处理请求的顺序（如下图）：<code>90、58、55、39、38、18、150、160、184</code></p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6%E6%9C%80%E7%9F%AD%E6%9C%8D%E5%8A%A1%E6%97%B6%E9%97%B4%E4%BC%98%E5%85%88.png" alt=""></p>
<ul>
<li>
<p>策略：选择使磁头臂从当前位置开始移动最少的磁盘I/O请求（如果两个距离相等，随机选择方向）</p>
</li>
<li>
<p>总是选择最小寻道时间的请求</p>
<blockquote>
<p>考虑的指标太单一，并不能保证平均寻道时间最小</p>
</blockquote>
</li>
<li>
<p>可能会产生饥饿</p>
<blockquote>
<p>如果不停有新的请求，该请求距离磁头很近，那么距离磁头较远的请求可能饥饿。</p>
</blockquote>
</li>
</ul>
<h4 id="SCAN（扫描，电梯算法）">SCAN（扫描，电梯算法）</h4>
<p>处理请求的顺序（如下图）：<code>55、58、39、18、90、160、150、38、184</code></p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSSCAN.png" alt=""></p>
<ul>
<li>
<p>策略：磁头臂仅沿一个方向移动，并在途中满足所有未完成的请求，直到它达到这个方向上的最后一个磁道，或者在这个方向上没有其他请求为止，反转扫描方向。</p>
<p>考虑了局部性原理</p>
<blockquote>
<p>这种定向移动的形式类似于电梯，因此也被称为“电梯算法”。</p>
</blockquote>
</li>
<li>
<p>可以解决饥饿</p>
</li>
<li>
<p>问题：基于该例假设，假设在处理完184号磁道请求之后，磁头反向扫描，这时又有新的185号磁道访问请求，那么磁头会扫描一轮之后再回来处理，显然是不合理的。</p>
</li>
</ul>
<h4 id="C-SCAN（循环扫描）">C-SCAN（循环扫描）</h4>
<p>处理请求的顺序（如下图）：<code>55、58、39、18、90、160、150、38、184</code></p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSCSCAN.png" alt=""></p>
<ul>
<li>策略：将扫描方向固定。当访问到沿某个方向的最后一个磁道时，磁头臂返回到磁道相反方向末端的磁道。</li>
<li>可以解决SCAN的问题。减少了新请求的最大延迟。</li>
</ul>
<h4 id="N-step-SCAN">N-step-SCAN</h4>
<ul>
<li>将磁盘请求队列划分为长度为N的n个子队列</li>
<li>对于n个子队列采取FIFO算法</li>
<li>对于子队列中的N个请求，采取SCAN算法</li>
<li>如果有新的请求，将其添加到新的队列中去</li>
</ul>
<h4 id="FSCAN">FSCAN</h4>
<ul>
<li>使用两个子队列</li>
<li>扫描开始时，所有请求都在一个队列中，另一个队列为空。</li>
<li>在扫描过程中，所有新到的请求都放入另一个队列。</li>
</ul>
<h4 id="磁盘调度算法比较">磁盘调度算法比较</h4>
<p>比较FIFO、SSTF、SCANF、C-SCAN算法，如下图：</p>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OS%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6%E6%AF%94%E8%BE%83.png" alt=""></p>
<blockquote>
<p>注意：计算平均寻道时间时，注意分母的取值。</p>
<p>以FIFO为例</p>
<ul>
<li>从磁道100处开始：</li>
</ul>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>A</mi><mi>V</mi><mi>E</mi><mo>=</mo><mfrac><mrow><mn>45</mn><mo>+</mo><mn>3</mn><mo>+</mo><mn>19</mn><mo>+</mo><mn>21</mn><mo>+</mo><mn>72</mn><mo>+</mo><mn>70</mn><mo>+</mo><mn>10</mn><mo>+</mo><mn>112</mn><mo>+</mo><mn>146</mn></mrow><mn>9</mn></mfrac><mo>=</mo><mn>55.3</mn></mrow><annotation encoding="application/x-tex">AVE = \frac{45+3+19+21+72+70+10+112+146}{9} = 55.3
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.00744em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">9</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">45</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">3</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">19</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">21</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">72</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">70</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">10</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">112</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">146</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">55.3</span></span></span></span></span></p>
<ul>
<li>从磁道55处开始：<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>A</mi><mi>V</mi><mi>E</mi><mo>=</mo><mfrac><mrow><mn>0</mn><mo>+</mo><mn>3</mn><mo>+</mo><mn>19</mn><mo>+</mo><mn>21</mn><mo>+</mo><mn>72</mn><mo>+</mo><mn>70</mn><mo>+</mo><mn>10</mn><mo>+</mo><mn>112</mn><mo>+</mo><mn>146</mn></mrow><mrow><mn>9</mn><mo>−</mo><mn>1</mn></mrow></mfrac><mo>=</mo><mn>56.625</mn></mrow><annotation encoding="application/x-tex">AVE = \frac{0+3+19+21+72+70+10+112+146}{9-1} = 56.625
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.09077em;vertical-align:-0.7693300000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">9</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">0</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">3</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">19</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">21</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">72</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">70</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">10</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">112</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">146</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.7693300000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">56.625</span></span></span></span></span></p>
</li>
</ul>
<p><strong>注意磁头开始的位置</strong></p>
</blockquote>
<h2 id="RAID">RAID</h2>
<p>受限于技术，磁盘存储器的大小并不能无限扩大，虽然技术在不断进步，其大小也在逐渐增大，但要意识到一个问题，现实中我们对于磁盘存储的需求可能要远远大于其实际容量。</p>
<p>设计人员认识到这个问题，并提出了并行使用多个磁盘的方案。</p>
<p>独立磁盘冗余阵列（Redundant Array of Independent Disks，RAID）：</p>
<ul>
<li>物理上通过多个磁盘组成一个磁盘组，在逻辑上这是一个大容量的磁盘</li>
<li>使用冗余磁盘容量保存奇偶检验信息，保证在一个磁盘失效时，数据具有可恢复性</li>
</ul>
<p>RAID包含0~6共七个级别，这里仅介绍RAID0、RAID1、RAID5</p>
<h4 id="RAID0">RAID0</h4>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSRAID0.png" alt=""></p>
<ul>
<li>实现高数据传送能力</li>
<li>实现告诉I/O请求率</li>
</ul>
<h4 id="RAID1">RAID1</h4>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSRAID1.png" alt=""></p>
<ul>
<li>读请求可由包含被请求数据的任何一个磁盘提供服务，而不管哪个磁盘拥有最小寻道时间和旋转延迟。</li>
<li>写请求需要对两个响应的条带进行更新，但这可并行完成。</li>
<li>从失效中恢复很简单：当一个驱动器失效时，仍然可以从第二个驱动器访问到数据。</li>
</ul>
<h4 id="RAID5">RAID5</h4>
<p><img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OSRAID5.png" alt=""></p>
<ul>
<li>把奇偶校验条带分布在所有磁盘中。</li>
</ul>
<hr>
<h1>后记</h1>
<p>本篇已完结</p>
<p>（如有修改或补充欢迎评论）</p>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">操作系统</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/wechat.png" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/wechat.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/alipay.jpg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2021/03/14/操作系统/操作系统学习笔记-计算机系统概述/" title="操作系统学习笔记-计算机系统概述"><img class="cover" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-14</div><div class="title">操作系统学习笔记-计算机系统概述</div></div></a></div><div><a href="/2021/03/28/操作系统/操作系统学习笔记/" title="操作系统学习笔记"><img class="cover" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/RotatingImage7.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-28</div><div class="title">操作系统学习笔记</div></div></a></div><div><a href="/2021/04/25/操作系统/操作系统学习笔记-信号量相关问题/" title="操作系统学习笔记-信号量相关问题"><img class="cover" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-04-25</div><div class="title">操作系统学习笔记-信号量相关问题</div></div></a></div><div><a href="/2021/05/23/操作系统/操作系统学习笔记-内存管理/" title="操作系统学习笔记-内存管理"><img class="cover" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-05-23</div><div class="title">操作系统学习笔记-内存管理</div></div></a></div><div><a href="/2021/05/30/操作系统/操作系统学习笔记-单处理器调度/" title="操作系统学习笔记-单处理器调度"><img class="cover" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-05-30</div><div class="title">操作系统学习笔记-单处理器调度</div></div></a></div><div><a href="/2021/05/04/操作系统/操作系统学习笔记-并发：死锁和饥饿/" title="操作系统学习笔记-并发：死锁和饥饿"><img class="cover" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/OperatingSystemscover1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-05-04</div><div class="title">操作系统学习笔记-并发：死锁和饥饿</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div><div id="comment-switch"><span class="first-comment">Twikoo</span><span class="switch-btn"></span><span class="second-comment">Valine</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">花猪</div><div class="author-info__description">此站点就暂时停留在秋天了吧</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">86</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/CNhuazhu"><i class="fab fa-github"></i><span>我的github</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/CNhuazhu" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">花猪在此欢迎您光临小破站 (՞•Ꙫ•՞) <br><b>此站点已暂停更新！！！！</b><br><br>  <b><i>本站已部署至云服务器👇</i></b>：<a href="http://cnhuazhu.top">http://cnhuazhu.top</a> <br><br>  <b><i>github地址（暂停更新）</i></b>：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://cnhuazhu.github.io/">https://cnhuazhu.github.io/</a> <br> <b><i>码云地址（暂停更新）</i></b>：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://cnhuazhu.gitee.io">https://cnhuazhu.gitee.io</a> <br><br>  本站主题：Butterfly 3.7.8 <br> <img src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/pig.gif"></div><timing></timing></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">2.</span> <span class="toc-text">第十一章：I&#x2F;O管理和磁盘调度</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#I-O%E8%AE%BE%E5%A4%87"><span class="toc-number">2.1.</span> <span class="toc-text">I&#x2F;O设备</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#I-O%E5%8A%9F%E8%83%BD%E7%9A%84%E7%BB%84%E7%BB%87"><span class="toc-number">2.2.</span> <span class="toc-text">I&#x2F;O功能的组织</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#I-O%E5%8A%9F%E8%83%BD%E7%9A%84%E5%8F%91%E5%B1%95"><span class="toc-number">2.2.1.</span> <span class="toc-text">I&#x2F;O功能的发展</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%B4%E6%8E%A5%E5%AD%98%E5%82%A8%E5%99%A8%E8%AE%BF%E9%97%AE%EF%BC%88DMA%EF%BC%89"><span class="toc-number">2.2.2.</span> <span class="toc-text">直接存储器访问（DMA）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E8%AE%BE%E8%AE%A1%E9%97%AE%E9%A2%98"><span class="toc-number">2.3.</span> <span class="toc-text">操作系统设计问题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BE%E8%AE%A1%E7%9B%AE%E6%A0%87"><span class="toc-number">2.3.1.</span> <span class="toc-text">设计目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#I-O%E5%8A%9F%E8%83%BD%E7%9A%84%E9%80%BB%E8%BE%91%E7%BB%93%E6%9E%84"><span class="toc-number">2.3.2.</span> <span class="toc-text">I&#x2F;O功能的逻辑结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#img-src-https-cdn-jsdelivr-net-gh-CNhuazhu-Image-OSIO%E5%B1%82%E6%AC%A1%E7%BB%93%E6%9E%84-png-style-zoom-80"><span class="toc-number">2.3.3.</span> <span class="toc-text"></span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#I-O%E7%BC%93%E5%86%B2"><span class="toc-number">2.4.</span> <span class="toc-text">I&#x2F;O缓冲</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8D%95%E7%BC%93%E5%86%B2"><span class="toc-number">2.4.1.</span> <span class="toc-text">单缓冲</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%8C%E7%BC%93%E5%86%B2"><span class="toc-number">2.4.2.</span> <span class="toc-text">双缓冲</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF%E7%BC%93%E5%86%B2"><span class="toc-number">2.4.3.</span> <span class="toc-text">循环缓冲</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6"><span class="toc-number">2.5.</span> <span class="toc-text">磁盘调度</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A3%81%E7%9B%98%E6%80%A7%E8%83%BD"><span class="toc-number">2.5.1.</span> <span class="toc-text">磁盘性能</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6%E7%AD%96%E7%95%A5"><span class="toc-number">2.5.2.</span> <span class="toc-text">磁盘调度策略</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BC%98%E5%85%88%E7%BA%A7%EF%BC%88Priority%EF%BC%8CPRI%EF%BC%89"><span class="toc-number">2.5.2.1.</span> <span class="toc-text">优先级（Priority，PRI）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%88%E8%BF%9B%E5%85%88%E5%87%BA%EF%BC%88First-in-First-out%EF%BC%8CFIFO%EF%BC%89"><span class="toc-number">2.5.2.2.</span> <span class="toc-text">先进先出（First-in First-out，FIFO）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%8E%E8%BF%9B%E5%85%88%E5%87%BA%EF%BC%88Last-in-First-out%EF%BC%8CLIFO%EF%BC%89"><span class="toc-number">2.5.2.3.</span> <span class="toc-text">后进先出（Last-in First-out，LIFO）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%80%E7%9F%AD%E6%9C%8D%E5%8A%A1%E6%97%B6%E9%97%B4%E4%BC%98%E5%85%88%EF%BC%88Shortest-Service-Time-First-%EF%BC%8CSSTF%EF%BC%89"><span class="toc-number">2.5.2.4.</span> <span class="toc-text">最短服务时间优先（Shortest Service Time First ，SSTF）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#SCAN%EF%BC%88%E6%89%AB%E6%8F%8F%EF%BC%8C%E7%94%B5%E6%A2%AF%E7%AE%97%E6%B3%95%EF%BC%89"><span class="toc-number">2.5.2.5.</span> <span class="toc-text">SCAN（扫描，电梯算法）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#C-SCAN%EF%BC%88%E5%BE%AA%E7%8E%AF%E6%89%AB%E6%8F%8F%EF%BC%89"><span class="toc-number">2.5.2.6.</span> <span class="toc-text">C-SCAN（循环扫描）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#N-step-SCAN"><span class="toc-number">2.5.2.7.</span> <span class="toc-text">N-step-SCAN</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#FSCAN"><span class="toc-number">2.5.2.8.</span> <span class="toc-text">FSCAN</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A3%81%E7%9B%98%E8%B0%83%E5%BA%A6%E7%AE%97%E6%B3%95%E6%AF%94%E8%BE%83"><span class="toc-number">2.5.2.9.</span> <span class="toc-text">磁盘调度算法比较</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#RAID"><span class="toc-number">2.6.</span> <span class="toc-text">RAID</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#RAID0"><span class="toc-number">2.6.0.1.</span> <span class="toc-text">RAID0</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#RAID1"><span class="toc-number">2.6.0.2.</span> <span class="toc-text">RAID1</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#RAID5"><span class="toc-number">2.6.0.3.</span> <span class="toc-text">RAID5</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">3.</span> <span class="toc-text">后记</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/11/02/NodeJS/%E5%BF%AB%E9%80%9F%E6%90%AD%E5%BB%BA%E4%B8%80%E4%B8%AAexpress%E6%9C%8D%E5%8A%A1%E5%99%A8/" title="快速搭建一个express服务器"><img src="https://gitee.com/CNhuazhu/tu-chuang1/raw/master/img-blog/Node_Express_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="快速搭建一个express服务器"/></a><div class="content"><a class="title" href="/2021/11/02/NodeJS/%E5%BF%AB%E9%80%9F%E6%90%AD%E5%BB%BA%E4%B8%80%E4%B8%AAexpress%E6%9C%8D%E5%8A%A1%E5%99%A8/" title="快速搭建一个express服务器">快速搭建一个express服务器</a><time datetime="2021-11-02T00:39:53.000Z" title="发表于 2021-11-02 08:39:53">2021-11-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/10/28/%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu%EF%BC%89/Nginx-uWSGI-Flask%E9%83%A8%E7%BD%B2%E8%87%B3Ubuntu/" title="Nginx+uWSGI+Flask部署至Ubuntu"><img src="https://gitee.com/CNhuazhu/tu-chuang1/raw/master/img-blog/Ubuntu_Server_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Nginx+uWSGI+Flask部署至Ubuntu"/></a><div class="content"><a class="title" href="/2021/10/28/%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu%EF%BC%89/Nginx-uWSGI-Flask%E9%83%A8%E7%BD%B2%E8%87%B3Ubuntu/" title="Nginx+uWSGI+Flask部署至Ubuntu">Nginx+uWSGI+Flask部署至Ubuntu</a><time datetime="2021-10-28T03:01:09.000Z" title="发表于 2021-10-28 11:01:09">2021-10-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/10/18/Xftp%E4%BC%A0%E8%BE%93%E6%96%87%E4%BB%B6%E5%A4%B1%E8%B4%A5%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/" title="Xftp传输文件失败解决方案"><img src="https://gitee.com/CNhuazhu/tu-chuang1/raw/master/img-blog/Xftp_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Xftp传输文件失败解决方案"/></a><div class="content"><a class="title" href="/2021/10/18/Xftp%E4%BC%A0%E8%BE%93%E6%96%87%E4%BB%B6%E5%A4%B1%E8%B4%A5%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/" title="Xftp传输文件失败解决方案">Xftp传输文件失败解决方案</a><time datetime="2021-10-18T09:50:16.000Z" title="发表于 2021-10-18 17:50:16">2021-10-18</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/10/13/%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu%EF%BC%89/Hexo%E9%83%A8%E7%BD%B2%E8%87%B3%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88%E7%BB%AD%EF%BC%89%E2%80%94%E2%80%94%E5%BB%BA%E7%AB%8B%E5%BC%95%E5%AF%BC%E9%A1%B5%E5%8F%8A%E5%88%86%E7%AB%99/" title="Hexo部署至服务器（续）——建立引导页及分站"><img src="https://gitee.com/CNhuazhu/tu-chuang1/raw/master/img-blog/Ubuntu_Server_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hexo部署至服务器（续）——建立引导页及分站"/></a><div class="content"><a class="title" href="/2021/10/13/%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu%EF%BC%89/Hexo%E9%83%A8%E7%BD%B2%E8%87%B3%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88%E7%BB%AD%EF%BC%89%E2%80%94%E2%80%94%E5%BB%BA%E7%AB%8B%E5%BC%95%E5%AF%BC%E9%A1%B5%E5%8F%8A%E5%88%86%E7%AB%99/" title="Hexo部署至服务器（续）——建立引导页及分站">Hexo部署至服务器（续）——建立引导页及分站</a><time datetime="2021-10-13T13:49:12.000Z" title="发表于 2021-10-13 21:49:12">2021-10-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/10/12/%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu%EF%BC%89/Hexo%E9%83%A8%E7%BD%B2%E8%87%B3%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu-20-04%EF%BC%89/" title="Hexo部署至服务器（Ubuntu 20.04）"><img src="https://gitee.com/CNhuazhu/tu-chuang1/raw/master/img-blog/Ubuntu_Server_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hexo部署至服务器（Ubuntu 20.04）"/></a><div class="content"><a class="title" href="/2021/10/12/%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu%EF%BC%89/Hexo%E9%83%A8%E7%BD%B2%E8%87%B3%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%88Ubuntu-20-04%EF%BC%89/" title="Hexo部署至服务器（Ubuntu 20.04）">Hexo部署至服务器（Ubuntu 20.04）</a><time datetime="2021-10-12T07:13:40.000Z" title="发表于 2021-10-12 15:13:40">2021-10-12</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 By 花猪</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a target="_blank" rel="noopener external nofollow noreferrer" href="http://beian.miit.gov.cn/">蜀ICP备2021026748号</a><br>感谢光临<a href="http://cnhuazhu.top/" style="text-decoration:underline">小破站</a>,欢迎您提出宝贵的意见！</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})
setTimeout(function(){preloader.endLoading();}, 3000);</script></div><div class="js-pjax"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css"><script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.css"><script>(() => {
  document.querySelectorAll('#article-container span.katex-display').forEach(item => {
    btf.wrap(item, 'div', '', 'katex-wrap')
  })
})()</script><script>(()=>{
  const $countDom = document.getElementById('twikoo-count')
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: 'hexo-1g41404w9f800e94',
      region: ''
    }, null))
  }

  const getCount = () => {
    twikoo.getCommentsCount({
      envId: 'hexo-1g41404w9f800e94',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      $countDom.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const loadTwikoo = (bool = false) => {
    if (typeof twikoo === 'object') {
      init()
      bool && $countDom && setTimeout(getCount,0)
    } else {
      getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js').then(()=> {
        init()
        bool && $countDom && setTimeout(getCount,0)
      })
    }
  }

  if ('Twikoo' === 'Twikoo' || !true) {
    if (true) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo(true)
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'VHoX95KsBQSMyzEc3TdpmBkF-MdYXbMMI',
      appKey: 'qnwObDMbgMEKnu1Gp8tk7PYJ',
      placeholder: '欢迎留下你的评论（昵称和邮箱为必填项）',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: false,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Twikoo' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script src="/js/ip_content.js"></script><script src="/js/timing.js"></script><script src="https://cdn.jsdelivr.net/gh/xiabo2/CDN@latest/fishes.js"></script><script src="/js/footer.js"></script><script src="/js/ginkgo-leaf.js"></script><script id="canvas_nest" defer="defer" color="0,0,0" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div class="pjax-reload"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__fadeInLeft');
    arr[i].setAttribute('data-wow-duration', '600ms');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__fadeInRightBig');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer="defer" src="https://cdn.jsdelivr.net/gh/graingert/wow@1.3.0/dist/wow.min.js"></script><script defer="defer" src="/js/wow_init.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
                        function butterfly_swiper_injector_config(){
                          var parent_div_git = document.getElementById('recent-posts');
                          var item_html = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="2021/03/28/Hexo魔改/Hexo魔改记录/" alt=""><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/RotatingImage4.jpg" alt=""/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-03-28</span><a class="blog-slider__title" href="2021/03/28/Hexo魔改/Hexo魔改记录/" alt="">Hexo魔改记录</a><div class="blog-slider__text">Hexo魔改记录</div><a class="blog-slider__button" href="2021/03/28/Hexo魔改/Hexo魔改记录/" alt="">详情   </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="2021/08/02/Vue/Vue学习笔记/" alt=""><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/RotatingImage5.jpg" alt=""/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-08-02</span><a class="blog-slider__title" href="2021/08/02/Vue/Vue学习笔记/" alt="">Vue学习笔记</a><div class="blog-slider__text">本文将介绍Vue的基础语法</div><a class="blog-slider__button" href="2021/08/02/Vue/Vue学习笔记/" alt="">详情   </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="2021/03/28/Java/Java学习记录/" alt=""><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/RotatingImage8.jpg" alt=""/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-03-28</span><a class="blog-slider__title" href="2021/03/28/Java/Java学习记录/" alt="">Java学习记录</a><div class="blog-slider__text">Java学习记录</div><a class="blog-slider__button" href="2021/03/28/Java/Java学习记录/" alt="">详情   </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="2021/03/28/操作系统/操作系统学习笔记/" alt=""><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/RotatingImage7.jpg" alt=""/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-03-28</span><a class="blog-slider__title" href="2021/03/28/操作系统/操作系统学习笔记/" alt="">操作系统学习笔记</a><div class="blog-slider__text">记录操作系统学习历程</div><a class="blog-slider__button" href="2021/03/28/操作系统/操作系统学习笔记/" alt="">详情   </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="2021/03/28/计算机网络/计算机网络学习笔记/" alt=""><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/CNhuazhu/Image/RotatingImage3.jpg" alt=""/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-03-28</span><a class="blog-slider__title" href="2021/03/28/计算机网络/计算机网络学习笔记/" alt="">计算机网络学习笔记</a><div class="blog-slider__text">记录计算机网络学习历程</div><a class="blog-slider__button" href="2021/03/28/计算机网络/计算机网络学习笔记/" alt="">详情   </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
                          console.log('已挂载butterfly_swiper')
                          // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                          parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
                          }
                        if( document.getElementById('recent-posts') && (location.pathname ==='all'|| 'all' ==='all')){
                        butterfly_swiper_injector_config()
                        }
                      </script><script defer src="https://cdn.jsdelivr.net/npm/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://cdn.jsdelivr.net/npm/hexo-butterfly-swiper/lib/swiper_init.js"></script><!-- hexo injector body_end end --><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/assets/tororo.model.json"},"display":{"superSample":2,"width":200,"height":400,"position":"left","hOffset":0,"vOffset":-105},"mobile":{"show":false,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body></html>